*****************************************************************************************************************************************************
* PROJECT: 		Exposure to the COVID-19 Stock Market Crash and its Effect on Household Expectations
* DATE: 		Nov 2020
* CONTENT: 		TABLES
* AUTHORS: 		Tobin Hanspal, Johannes Wohlfart, Anni Weber
*****************************************************************************************************************************************************

		clear all
		set scheme lean2
		global pm = char(177)
		set more off
		gl date = c(current_date)
		graph set window fontface "cmr10"		
		
* set cd as /Replication_files_HanspalWeberWohlfart2020/


*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~						
** Table A2
*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~	
	
use data/processed/data_1, clear 
			   
loc covars "female age atleast_bachelor hhinc_lvl republican democrat midwest south west  stockinvestor "

/* Balance tables */
    preserve

    clear all
    eststo clear
    estimates drop _all

    set obs 10
    qui gen x = 1
    qui gen y = 1

    forval i = 1/9 {

        qui eststo col`i': reg x y

    }

    restore

/* Statistics */

    loc tabletitle "Randomization check for experiment `expid'"
    loc rowstats ""
    loc rowlabels ""
    loc colnames " "FinCrisisInfo" "FinCrisisControl" "DotComInfo" "DotComControl"  "BlackMondayInfo" "BlackMondayControl" "PureControl"  "P-value" "Observations" "

    loc varlength: list sizeof covars
    loc varindex = 1

    mat def P1 = J(`varlength', 1, .)
    mat def P2 = J(`varlength', 1, .)
    mat def P3 = J(`varlength', 1, .)

    foreach var in `covars' {


        cap noi {
            qui sum `var' if treatment == 1 
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col1
        }

        cap noi {
            qui sum `var' if treatment == 2
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col2
        }


		   cap noi {
            qui sum `var' if treatment == 3
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col3
        }
		
		   cap noi {
            qui sum `var' if treatment == 4
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col4
        }
		
		   cap noi {
            qui sum `var' if treatment == 5
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col5
        }
		
		   cap noi {
            qui sum `var' if treatment == 6
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col6
        }
		
		   cap noi {
            qui sum `var' if treatment == 0
            estadd loc `var'_mean = string(r(mean), "%9.2f"): col7
        }
		
	

        cap noi {
            qui reg `var' i.treatment, vce(r)
            qui test (1.treatment=0) (2.treatment=0) (3.treatment=0)  (4.treatment=0)  (5.treatment=0)  (6.treatment=0)
            estadd loc `var'_mean = string(r(p), "%9.3f"): col8
            mat def P3[`varindex', 1] = r(p)
        }
		
				
				 cap noi {
            qui sum `var' 
            estadd loc `var'_mean =  string(r(N), "%9.0f"): col9
        }

        loc rowstats "`rowstats' `var'_mean `var'_sd"
        loc rowlabels "`rowlabels' `"`: var la `var''"' " " "

        loc ++varindex

    }
	
    esttab * using "Tables/TableA3.tex", replace cells(none) booktabs nonotes nonum compress alignment(c) nogap noobs nobaselevels label mtitle(`colnames') stats(`rowstats', labels(`rowlabels'))
    eststo clear





